package com.wtwd.device.util;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

/**
 * @author zdl
 * @Description
 * @create 2021-08-09 11:27
 */
public class SMSTwilioUtil {
    // Find your Account Sid and Auth Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACf82b11ff4d427a2d872cff48f2be2444";
    public static final String AUTH_TOKEN = "dddd7defe75268d0180597503ed8b4b4";
    public static final String signName = "[tracker]";
    public static final String from_phone = "+19893092688";

    public static void main(String[] args) {
        sendVerifyCode("+6309272577462", "这是验证吗${code}", "365");
    }


    public static String sendVerifyCode(String userPhone, String content, String code) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        String resultCode = "";

        // TODO  短信内容待修改
        try {
            content = StringUtil.replaceTemplateParams(content, "{code:'" + code + "'}");
            Message message = Message.creator(new PhoneNumber(userPhone), new PhoneNumber(from_phone), content).create();
            resultCode = message.getStatus().toString();
        } catch (Exception e) {
        }
        return resultCode;

    }

}
